package com.ty;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.util.Map;

@SpringBootApplication
//@SpringBootConfiguration
//@EnableAutoConfiguration
//@ComponentScan(basePackages = "com.ty")
public class SpringbootDemoApplication {


  public static void main(String[] args) {
    //返回IOC容器
    ConfigurableApplicationContext context = SpringApplication.run(SpringbootDemoApplication.class, args);
    System.out.println("context.getBeanDefinitionCount() = " + context.getBeanDefinitionCount());

    //name = redisTemplate
    //name = stringRedisTemplate
    RedisTemplate redisTemplate = (RedisTemplate) context.getBean("redisTemplate");
    ValueOperations ops = redisTemplate.opsForValue();
    ops.set("k1111","sadacz");
    System.out.println("redisTemplate.hasKey(\"k1111\") = " + redisTemplate.hasKey("k1111"));


    RedisTemplate<String, String> stringRedisTemplate = (StringRedisTemplate) context.getBean("stringRedisTemplate");
    ValueOperations<String, String> value = stringRedisTemplate.opsForValue();
    value.set("string1","values1");
    System.out.println("stringRedisTemplate.hasKey(\"string1\") = " + stringRedisTemplate.hasKey("string1"));



//    for (String name : context.getBeanDefinitionNames()) {
//      System.out.println("name = " + name);
//    }
    context.close();
  }
}
